package com.liusy.code.templates;

import com.liusy.code.bean.*;

public class ServiceImplTemplate
{
  protected static String nl;
  public static synchronized ServiceImplTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    ServiceImplTemplate result = new ServiceImplTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "" + NL + "import java.util.HashMap;" + NL + "import java.util.List;" + NL + "import java.util.Map;" + NL + "" + NL + "import org.apache.shiro.SecurityUtils;" + NL + "import org.springframework.beans.factory.annotation.Autowired;" + NL + "import org.springframework.stereotype.Service;" + NL + "import org.springframework.transaction.annotation.Propagation;" + NL + "import org.springframework.transaction.annotation.Transactional;" + NL + "" + NL + "import com.gdtopway.framework.common.dao.extend.IExtendBaseDAO;" + NL + "import com.gdtopway.framework.right.constants.LoginConstants;" + NL + "import com.gdtopway.framework.right.domain.Account;" + NL + "import com.gdtopway.zhaobiao.util.PageContent;" + NL + "import com.gdtopway.zhaobiao.util.PageRequest;" + NL + "" + NL + "import ";
  protected final String TEXT_3 = ".";
  protected final String TEXT_4 = ";" + NL + "import ";
  protected final String TEXT_5 = ".";
  protected final String TEXT_6 = ";" + NL + "import ";
  protected final String TEXT_7 = ".";
  protected final String TEXT_8 = ";" + NL + "" + NL + "/**" + NL + " * " + NL + " * " + NL + " * @author " + NL + " * " + NL + " */" + NL + "@Service(\"";
  protected final String TEXT_9 = "\")" + NL + "public class ";
  protected final String TEXT_10 = " implements ";
  protected final String TEXT_11 = " {" + NL + "\t" + NL + "\t" + NL + "\t@Autowired" + NL + "\tprivate ";
  protected final String TEXT_12 = " ";
  protected final String TEXT_13 = ";" + NL + "" + NL + "\t@Autowired" + NL + "\tprivate IExtendBaseDAO extendBaseDAO;" + NL + "\t" + NL + "\t@Override" + NL + "\t@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)" + NL + "\tpublic ";
  protected final String TEXT_14 = " save(";
  protected final String TEXT_15 = " ";
  protected final String TEXT_16 = ") {" + NL + "\t\t//Account account = (Account) SecurityUtils.getSubject().getSession().getAttribute(LoginConstants.ACCOUNT_OBJ);" + NL + "\t\t//";
  protected final String TEXT_17 = ".setChuliren(account.getName());" + NL + "\t\t//";
  protected final String TEXT_18 = ".setChulirenid(account.getId().toString());" + NL + "\t\treturn this.";
  protected final String TEXT_19 = ".save(";
  protected final String TEXT_20 = ");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic ";
  protected final String TEXT_21 = " get(String id) {" + NL + "\t\treturn this.";
  protected final String TEXT_22 = ".get(id);" + NL + "\t}" + NL + "\t" + NL + "\t@Override" + NL + "\t@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)" + NL + "\tpublic void delete(String id){" + NL + "\t\tthis.";
  protected final String TEXT_23 = ".removeById(id);" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\t@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)" + NL + "\t\tpublic ";
  protected final String TEXT_24 = " update(";
  protected final String TEXT_25 = " ";
  protected final String TEXT_26 = ") {" + NL + "\t\treturn this.";
  protected final String TEXT_27 = ".update(";
  protected final String TEXT_28 = ");" + NL + "\t}" + NL + "" + NL + "\t@Override" + NL + "\tpublic List<";
  protected final String TEXT_29 = "> get";
  protected final String TEXT_30 = "List(){" + NL + "\t\tString sql = \"select * from ";
  protected final String TEXT_31 = " \";" + NL + "\t\ttry {" + NL + "\t\t\tList<";
  protected final String TEXT_32 = "> list = this.extendBaseDAO.findListByNativeSQL(";
  protected final String TEXT_33 = ".class, sql, new HashMap<String, Object>());" + NL + "\t\t\t\treturn list;" + NL + "\t\t} catch (Exception e) {" + NL + "\t\t\te.printStackTrace();" + NL + "\t\t}" + NL + "\t\treturn null;" + NL + "\t}" + NL + "\t" + NL + "\t" + NL + "\t@Override" + NL + "\tpublic PageContent find";
  protected final String TEXT_34 = "List(PageRequest pageRequest, Map<String, String> queryParam){" + NL + "\t\tString sql = \"select * from ";
  protected final String TEXT_35 = " \";" + NL + "\t\tPageContent pageContent = new PageContent();" + NL + "\t\ttry {" + NL + "\t\t\tList<Map<String, Object>> list = this.extendBaseDAO.findMapListByNativeSQL(sql,new HashMap<String, Object>(), pageRequest.getRows(),pageRequest.getPage());" + NL + "\t\t\tint count = this.extendBaseDAO.findRowCountByNativeSQL(sql, new HashMap<String, Object>());" + NL + "\t\t\tpageContent.setContent(list);" + NL + "\t\t\tpageContent.setRowCount(count);" + NL + "\t\t} catch (Exception e) {" + NL + "\t\t\te.printStackTrace();" + NL + "\t\t}" + NL + "\t\treturn pageContent;" + NL + "\t}" + NL + "\t" + NL + "}";
  protected final String TEXT_36 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
	JavaTemplateArgs args = (JavaTemplateArgs)argument;

    stringBuffer.append(TEXT_1);
    stringBuffer.append(args.getPackageName());
    stringBuffer.append(TEXT_2);
    stringBuffer.append(args.getPackageNameInfo().getDaoPackageName());
    stringBuffer.append(TEXT_3);
    stringBuffer.append(args.getClassNameInfo().getDaoClassName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(args.getPackageNameInfo().getEntityPackageName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(args.getPackageNameInfo().getServicPackageName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(args.getClassNameInfo().getServicClassName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(args.getClassNameInfo().getServicObjectName());
    stringBuffer.append(TEXT_9);
    stringBuffer.append(args.getClassNameInfo().getServicClassNameImpl());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(args.getClassNameInfo().getServicClassName());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(args.getClassNameInfo().getDaoClassName());
    stringBuffer.append(TEXT_12);
    stringBuffer.append(args.getClassNameInfo().getDaoObjectName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(args.getClassNameInfo().getEntityObjectName());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(args.getClassNameInfo().getEntityObjectName());
    stringBuffer.append(TEXT_17);
    stringBuffer.append(args.getClassNameInfo().getEntityObjectName());
    stringBuffer.append(TEXT_18);
    stringBuffer.append(args.getClassNameInfo().getDaoObjectName());
    stringBuffer.append(TEXT_19);
    stringBuffer.append(args.getClassNameInfo().getEntityObjectName());
    stringBuffer.append(TEXT_20);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_21);
    stringBuffer.append(args.getClassNameInfo().getDaoObjectName());
    stringBuffer.append(TEXT_22);
    stringBuffer.append(args.getClassNameInfo().getDaoObjectName());
    stringBuffer.append(TEXT_23);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_24);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_25);
    stringBuffer.append(args.getClassNameInfo().getEntityObjectName());
    stringBuffer.append(TEXT_26);
    stringBuffer.append(args.getClassNameInfo().getDaoObjectName());
    stringBuffer.append(TEXT_27);
    stringBuffer.append(args.getClassNameInfo().getEntityObjectName());
    stringBuffer.append(TEXT_28);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_29);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_30);
    stringBuffer.append(args.getTableName());
    stringBuffer.append(TEXT_31);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_32);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_33);
    stringBuffer.append(args.getClassNameInfo().getEntityClassName());
    stringBuffer.append(TEXT_34);
    stringBuffer.append(args.getTableName());
    stringBuffer.append(TEXT_35);
    stringBuffer.append(TEXT_36);
    return stringBuffer.toString();
  }
}
